﻿@{ Webcar.Controllers.ShowCarOptions options = (Webcar.Controllers.ShowCarOptions)ViewBag.ShowOptions; }
@{ Layout = "~/Views/Shared/_leftPanelLayout.cshtml";}
@section LeftTree
{
     
    @{
        Html.RenderPartial("DeptTreePartialView", new Webcar.Models.DeptTreeMode { Action = "List", Controller = "Car", ShowChild = true, ShowNumber=true, AutoRedirect = true });
     }
}

@using (Ajax.BeginForm("ListPartialView", "Car",Html.ViewContext.RouteData.Values, new AjaxOptions
    {
        HttpMethod = "POST",
        UpdateTargetId = "list-car",
        InsertionMode = System.Web.Mvc.Ajax.InsertionMode.Replace
    }))
    { 
        @UserQuery.CreateQuery(setting => {
       setting.QueryKey = QuerySettings.CarList;
           setting.Columns.Add(new QueryColumn() { Field = "RECORD_NO", Name = "牌照号" });
           setting.Columns.Add(new QueryColumn() { Field = "CAR_SORT", Name = "车型",DataType = TypeofQueryColumn.DropDownList, CallBackAction = Url.Action("QueryCarSort", "Common") });
           setting.Columns.Add(new QueryColumn() { Field = "CAR_CLASS_NAME", Name = "详细车型" });
           setting.Columns.Add(new QueryColumn() { Field = "BUY_DATE", Name = "购置时间", DataType = TypeofQueryColumn.Date });
           setting.Columns.Add(new QueryColumn() { Field = "INSURE_DATE", Name = "保险到期日期", DataType = TypeofQueryColumn.Date });
           setting.Columns.Add(new QueryColumn() { Field = "VALUE", Name = "价格", DataType = TypeofQueryColumn.Number });
           setting.Columns.Add(new QueryColumn() { Field = "GUEST_NUM", Name = "客位数", DataType = TypeofQueryColumn.Number });
        })
}
@using (Html.BeginForm()) {
    <div style="margin-bottom:1px;">
        @Html.CheckBox("ShowNormal", options.ShowNormal)
        <label for="ShowNormal">显示正常车辆</label>
        @Html.CheckBox("ShowDiscard", options.ShowDiscard)
        <label for="ShowDiscard">显示报废车辆</label>
        @Html.CheckBox("ShowDelete", options.ShowDelete)
        <label for="ShowDelete">显示删除车辆</label>
        &nbsp;
        &nbsp;
        @Html.SubmitButton("btnApply", "应用")
    </div>
}
<hr />
<div id="list-car">
    
    @Html.Action("ListPartialView")
</div>


<hr />
<input value="增加车辆" class="webcar-button" type="button" onclick="addcar();" />
<input value="导出EXCEL" class="webcar-button" type="button" onclick="export_xls();" />

@* @Html.DevExpress().Button(settings =>
{
    settings.Name = "Button1";
    settings.Text = "增加车辆";
    settings.Width = 120;
    settings.ControlStyle.CssClass = "button1";
    
    settings.ClientSideEvents.Click = "function(s, e){ addcar(); }";
}).GetHtml()*@

<script type="text/javascript">
    var carNo = null;
    var dept = null;
    function addcar() {
        carNo = "";
        dept = '@Html.ViewContext.RouteData.Values["id"]';
        pcModalMode.Show();
    }
    function edit(carno) {
        carNo = carno;
        pcModalMode.Show();
    }
    function move(carno) {
        carNo = carno;
        pcModalModeMove.Show();
    }
    function discard(carno) {
        carNo = carno;
        pcModalModeDiscard.Show();
    }

    function OnBeginCallback(s, e) {
        e.customArgs["carno"] = carNo;
        e.customArgs["deptcode"] = dept;
        carNo = "";
        dept = "";
    }
    function OnEndCallback(s, e) {
    }
    function deletecar(url) {
        if (confirm("删除车辆将同时删除车辆的所有信息，是否要继续删除？") == false) return;
        location.href = url;
    }
    function deletecar2(url) {
        if (confirm("是否要删除选定的车辆？") == false) return;
        location.href = url;
    }
    function showPic(car_no) {
        var image_div = $("#div_image");
        var image_url = $("#img_" + car_no).val();
        
        if (image_url == null || image_url == "") {
            if (image_div.length > 0) {
                image_div.remove();
            }
            return;
        }
        if (image_div.length == 0) {
            var image_html = "<img id='div_imgshow' style='max-width:600px;max-height:400px;' src='" + image_url + "'/>";
            image_div = $("<div id='div_image' style='z-index:999;position:absolute;top:" + window.event.clientY + "px;left:" + window.event.clientX + "px;'>" +
                image_html+"</div>");
        }
        var h = document.body.clientHeight - window.event.clientY;
        //alert(h);
        if (h < 400) {
            image_div.css("top", window.event.clientY - 400);
            image_div.css("left", window.event.clientX);
        }
        else {
            image_div.css("top", window.event.clientY);
            image_div.css("left", window.event.clientX);
        }
        $("#div_imgshow").attr("src", image_url);
        image_div.mouseleave(function () {
            $(this).remove();
        });
        $(document.body).append(image_div);
    }
    function export_xls() {
        location.href='@Url.Action("Export", "Car", Html.ViewContext.RouteData.Values)';
    }

    function fn_is_tz_check(id) {
        var check_contrl = $("#tz_" + id);
        var check_flag = false;
        if (check_contrl.attr("checked")) {
            check_flag = true;
        }
        else {
            check_flag = false;
        }
        //ajax
        var action = '@Url.Action("SetTzFlag","Car")';
        $.get(action, { id: id, tz_flag: check_flag },
            function (data) {

            });
    }
</script>

@Html.DevExpress().PopupControl(
settings =>
{
    settings.Name = "pcModalMode";
    settings.CallbackRouteValues = new { Controller = "Car", Action = "Edit"};
    settings.Width = 610;
    settings.Height = 440;
    settings.InitDefaultSettings();
    settings.HeaderText = "车辆信息编辑";
}).GetHtml()

@Html.DevExpress().PopupControl(
settings =>
{
    settings.Name = "pcModalModeMove";
    settings.CallbackRouteValues = new { Controller = "Car", Action = "Move"};
    settings.Width = 410;
    settings.Height = 350;
    settings.InitDefaultSettings();
    settings.HeaderText = "车辆调动";
}).GetHtml()

@Html.DevExpress().PopupControl(
settings =>
{
    settings.Name = "pcModalModeDiscard";
    settings.CallbackRouteValues = new { Controller = "Car", Action = "Discard" };
    settings.Width = 410;
    settings.Height = 300;
    settings.InitDefaultSettings();
    settings.HeaderText = "车辆报废";
}).GetHtml()

